import 'package:flutter_frontend/utils/http_manager.dart';
import 'package:flutter_frontend/utils/app_manager.dart';

class LoginApi {
  LoginApi._();

  /// 用户名密码登录接口
  /// username 用户名
  /// password 密码
  /// captchaCode 图形验证码
  static Future<String?> loginAccount({required String username, required String password}) async {
    final String? uuid = await AppManager.sharedInstance.uuid;
    final Map<String, dynamic> param = {'username': username, 'password': password, 'login_type': 2, 'client': 'app', 'captcha_uuid': uuid};
    final ApiCallBackInfo info = await HttpManager().requestData('/api/global_service/web/area/login/', httpMethod: HttpMethod.post, data: param);
    if (info.code == 0) {
      final AppManager manager = AppManager();
      manager.setToken(info.data['token']);
      return null;
    }
    return info.message;
  }
}
